Skip to content

refactor(users): migrate remaining Python is_staff checks to is_staff_user (#174)#179

Open
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
b3lz3but:refactor/is-staff-user-migration
Open

refactor(users): migrate remaining Python is_staff checks to is_staff_user (#174)#179
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
b3lz3but:refactor/is-staff-user-migration

Conversation

@b3lz3but
Copy link
Copy Markdown
Contributor

@b3lz3but b3lz3but commented Apr 16, 2026

Summary

  • decorators.py: can_manage_financial_data now gates on is_staff_user so staff-by-role users (staff_role="admin" with is_staff=False) are correctly recognized
  • context_processors.py: can_access_admin uses is_staff_user with getattr guard for AnonymousUser safety
  • permissions.py: can_deploy_nodes uses is_staff_user so support agents with deploy perms aren't locked out
  • orders/views.py: _validate_manual_price_override uses is_staff_user and cleaned hasattr to getattr pattern

Not migrated (intentionally)

  • Role-specific checks (staff_role in _REVIEW_APPROVE_ROLES, billing_staff_required, support_staff_required) — these gate specific roles, not generic staff access
  • Audit metadata (is_staff in audit/services.py) — records the raw Django flag for compliance
  • API response fields (is_staff in api/users/views.py) — changing would be a breaking API change

Test plan

  • Permission matrix test updated: staff_role="admin" with is_staff=False now correctly returns True for can_manage_financial_data
  • Staff role classification tests pass (22/22)
  • mypy clean on all 4 modified files

Addresses #174

🤖 Generated with Claude Code

Closes #174

…_user (captainpragmatic#174)

- decorators.py: can_manage_financial_data now gates on is_staff_user so
  staff-by-role users (staff_role="admin" with is_staff=False) are correctly
  recognized as staff for financial data management
- context_processors.py: can_access_admin uses is_staff_user with getattr
  guard for AnonymousUser safety
- permissions.py: can_deploy_nodes uses is_staff_user so support agents with
  deploy perms are no longer locked out
- orders/views.py: _validate_manual_price_override uses is_staff_user and
  cleaned up hasattr guards to getattr pattern
- Update permission_matrix test to reflect that staff_role="admin" users are
  now correctly classified as staff regardless of is_staff flag

Role-specific checks (staff_role in _REVIEW_APPROVE_ROLES, billing_staff_required,
support_staff_required) are intentionally kept — they gate specific roles, not
generic staff access. Audit metadata fields (is_staff in audit/services.py) and
API response fields (is_staff in api/users/views.py) are intentionally unchanged
as they record the raw Django flag, not the computed property.

Addresses captainpragmatic#174.

Signed-off-by: Ciprian Radulescu <craps2003@gmail.com>
@b3lz3but
Copy link
Copy Markdown
Contributor Author

@mostlyvirtual CI green — migrates the permission-check locations to is_staff_user. Role-specific guards, audit metadata, and API fields intentionally unchanged. Ready for review 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(users): migrate remaining ~20 is_staff/staff_role checks to is_staff_user

1 participant